package base

import (
	"go_gvm_mini/rtda"
	"go_gvm_mini/rtda/heap"
)

func InvokeMethod(invokeJFrame *rtda.JFrame, method *heap.Method) {
	jThread := invokeJFrame.JThread()
	newJFrame := jThread.NewFrame(method)
	jThread.PushJFrame(newJFrame)
	argSlotCount := int(method.ArgSlotCount())
	if argSlotCount > 0 {
		for i := 0; i < argSlotCount; i++ {
			slot := invokeJFrame.OperandStack().PopSlot()
			newJFrame.LocalVars().SetSlot(uint(i), slot)
		}
	}
}
